package com.lyy.fallback;

import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;

/**
 * @author Liangyaoyun
 */
public class SentinelFallback {
    public static String fallback(Throwable e){
        String Message=e.getMessage();
        if (e instanceof FlowException){
            Message = "FlowException流控异常: 您访问的太快或当前访问人数过多，请稍后重试..";
        } else if (e instanceof DegradeException) {
            Message="DegradeException熔断异常: 服务器响应超时或失败次数过多，请稍后重试..";
        } else if (e instanceof AuthorityException) {
            Message= "AuthorityException授权异常: 您无权访问该资源，请联系管理员..";
        } else if (e instanceof SystemBlockException) {
            Message="SystemBlockException系统异常: 系统限制，Sentinel熔断降级..";
            
        }
        System.out.println(Message);
        return Message;
    }
}
